package cn.tedu.blog.server.controller.system;

import cn.tedu.blog.server.pojo.dto.CategoryAddDTO;
import cn.tedu.blog.server.pojo.vo.CategoryDetailVO;
import cn.tedu.blog.server.service.ICategoryService;
import cn.tedu.blog.server.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author blue
 * @description: 后台系统类别管理控制器
 * @date
 */
@Api(tags = "3. 类别管理")
@Slf4j
@RestController
@RequestMapping("/system/category")
public class CategoryController {


    @Autowired
    private ICategoryService categoryService;

    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody CategoryAddDTO categoryAddDTO){
        log.debug("接收到的请求参数：{}", categoryAddDTO);
        categoryService.addNew(categoryAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除类别")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        log.debug("接收到删除类别的请求");
        categoryService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改类别")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult update(@RequestBody CategoryAddDTO categoryAddDTO){
        log.debug("接收到修改类别的请求");
        categoryService.updateById(categoryAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询类别")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list(){
        log.debug("接收到查询类别的请求");
        List<CategoryDetailVO>list=categoryService.list();
        return JsonResult.ok(list);
    }
//
//    @Autowired
//    private ICategoryService categoryService;
//
//
//    @ApiOperation("1. 创建类别")
//    @ApiOperationSupport(order = 100)
//    @PostMapping("/insert")
//    public JsonResult insert(@RequestBody CategoryAddDTO categoryAddDTO){
//        log.debug("接收到客户端提交的创建类别请求，参数：{}",categoryAddDTO);
//        categoryService.insert(categoryAddDTO);
//        return JsonResult.ok();
//    }
//
//    @ApiOperation("2. 删除类别")
//    @ApiOperationSupport(order = 200)
//    @PostMapping("/delete")
//    public JsonResult delete(@RequestBody CategoryAddDTO categoryAddDTO){
//        log.debug("接收到客户端提交的删除类别请求，参数：{}",categoryAddDTO.getId());
//        categoryService.delete(categoryAddDTO.getId());
//        return JsonResult.ok();
//    }
//
//    @ApiOperation("3. 修改类别")
//    @ApiOperationSupport(order = 300)
//    @PostMapping("/update")
//    public JsonResult update(@RequestBody CategoryAddDTO categoryAddDTO){
//        log.debug("接收到客户端提交的修改类别请求，参数：{}",categoryAddDTO);
//        categoryService.update(categoryAddDTO);
//        return JsonResult.ok();
//    }
//
//
//    @ApiOperation("4. 查询类别")
//    @ApiOperationSupport(order = 400)
//    @PostMapping("/listMenu")
//    public List<CategoryListVO> listMenu(@RequestBody CategoryListVO categoryListVO){
//        log.debug("接收到客户端提交的条件分页查询类别请求，参数：{}",categoryListVO);
//        return categoryService.list(categoryListVO);
//    }
//
//
//    @PostMapping("/countAll")
//    public int getCountAll(@RequestBody CategoryListVO categoryListVO){
//        log.debug("【countAll】接收到客户端提交的请求，参数：{}",categoryListVO);
//        return categoryService.getCountAll(categoryListVO);
//    }
//
//
//    @GetMapping("/getBackFillById")
//    public CategoryListVO getBackFillById(Long id){
//        log.debug("接收到客户端提交的请求，参数：{}",id);
//        return categoryService.getBackFillById(id);
//    }

}